<?php
class appException extends Exception{
 	private $type;
    private $extra;
	public function __construct($message, $code=null,$extra=true){
		parent::__construct($message, $code);	
		$this->type = get_class($this);
        $this->extra = $extra;	
		$this->showError();
	}
	
	public function showError(){
		@$trace = $this->getTrace();
        if($this->extra)
            array_shift($trace); 
        $traceInfo=null;
        $time = date("y-m-d H:i:m");
        foreach($trace as $t) {
            @$traceInfo .= '['.$time.'] '.$t['file'].' ('.$t['line'].') ';
            @$traceInfo .=$t['function'].'(';
            @$traceInfo .= implode(', ', $t['args']);
            @$traceInfo .=")\n";
        }
        $error['type']      = $this->type;
        $error['class']     =   $this->type;
        $error['line']      = $this->getLine();
 		if (TK_DEBUG){
        	$error['message']   = $this->getMessage();
	        $error['file']      = $this->getFile();
	        $error['trace']     = $traceInfo;
 			include 'Exception.tpl.php';
 		}else{
 			$error['message']  =  "{$this->getMessage()} 错误ID:".$this->getLine();
 			include 'Exception.tpl.php';
 		}
	}
	
	function __destruct() {
		exit();
	}
}